<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div></div>
    <script>
        //获取元素
        var div = document.querySelector('div');
        //得到当前时间
        var h = new Date().getHours();
        //判断时间对应文字
        if(h<6){
            document.write('凌晨好')
        }else if(h<9){
            document.write('早上好')
        }else if (h<12){
            document.write('上午好')
        }else if (h<14){
            document.write('中午好')
        }else if (h<17){
            document.write('下午好')
        }else if (h<19){
            document.write('傍晚好')
        }else if (h<22){
            document.write('晚上好')
        }else if (h>=22){
            document.write('夜里好')
        }
    </script>
</body>
</html>